﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Script.Services;
using System.Web.Services;
using System.Text;
using System.Web.Script.Services;
using System.Xml.Linq;
using OrganizedIN.DAL;
using OrganizedIN.BAL;
using OrganizedIN.BussinessServices;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using OrganizedIN.BAL.Common;


namespace OrganizedIN.UI.ToDo
{
    public partial class search_todos : System.Web.UI.Page
    {
        string strUserName;
        static string _strUserID;
        public string sp = string.Empty;
        public string sp_holder; //Sets the Public Property StoredProc

        public string StoredProc
        {
            get
            {
                return sp_holder;
            }
            set
            {
                sp_holder = value;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            strUserName = Convert.ToString(Session["UserID"]);           
           
        }

        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static string[] GetCompletionList(string prefixText)
        {
            //strUserName = Convert.ToString(Session["UserID"]);
            DataSet ds = new DataSet();
            ds = Common.AjaxSearchDemo(prefixText);                        
            List<string> cityList = new List<string>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                cityList.Add(ds.Tables[0].Rows[i][0].ToString());
            }
            return cityList.ToArray();
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                string strPriority = String.Empty;
                int intDay = 0;
                string strUserName = Session["UserID"].ToString();

                MyProfileTodo objMyTodo = new MyProfileTodo();
                objMyTodo.TodoSummary = txtSearchByTitle.Text;
                objMyTodo.ToDoCreateDate = txtSearchByDate.Text;
                string strSort = ddlSort.SelectedValue.ToString();

                if (ddlPriority.SelectedValue.ToString() == "0")
                {
                    strPriority = "";
                }
                else
                {
                    strPriority = ddlPriority.SelectedItem.Text;
                }

                if (ddlDays.SelectedValue.ToString() != "0")
                {
                    intDay = Convert.ToInt32(ddlDays.SelectedValue.ToString());
                }

                DataSet ds = new DataSet();
                ds = Common.Get_Todo_SearchResult(strUserName, objMyTodo.TodoSummary, objMyTodo.ToDoCreateDate, strPriority, intDay, strSort);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    dgSearchResult.Visible = true;
                    lblErrMsg.Text = "";
                    dgSearchResult.DataSource = ds.Tables[0];
                    dgSearchResult.DataBind();
                }
                else
                {
                    dgSearchResult.Visible = false;
                    lblErrMsg.Text = "No record(s) found.";
                }
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = ex.ToString();
            }
        }

        
    }
}
